package org.example.mapper;

import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserRoleMapper {

    // 插入用户角色关联
    @Insert("INSERT INTO user_role (user_id, role_id) VALUES (#{userId}, #{roleId})")
    void insertUserRole(@Param("userId") Long userId, @Param("roleId") Long roleId);

    // 查询用户的所有角色
    @Select("SELECT role_id FROM user_role WHERE user_id = #{userId}")
    List<Long> getRolesByUserId(@Param("userId") Long userId);

    // 查询角色的所有用户
    @Select("SELECT user_id FROM user_role WHERE role_id = #{roleId}")
    List<Long> getUsersByRoleId(@Param("roleId") Long roleId);

    // 删除用户的角色
    @Delete("DELETE FROM user_role WHERE user_id = #{userId} AND role_id = #{roleId}")
    void deleteUserRole(@Param("userId") Long userId, @Param("roleId") Long roleId);
}
